// logindialog.h
#ifndef LOGINDIALOG_H
#define LOGINDIALOG_H

#include <QDialog>
#include <QPropertyAnimation>
#include "client_network.h"
#include "request_sender.h"

#include"request_sender.h"
QT_BEGIN_NAMESPACE
namespace Ui { class LoginDialog; }
QT_END_NAMESPACE

class LoginDialog : public QDialog
{
    Q_OBJECT

signals:
    void requestShowRegister();  // 请求显示注册界面
    void requestClose();        // 请求关闭自己
    void loginSuccess(const QString &username);

public:
    explicit LoginDialog(RequestSender *requestSender,ClientNetwork *clientNet,QWidget *parent = nullptr);
    ~LoginDialog();

    QString username() const;
    QString password() const;
    void clearFields();

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;
    void paintEvent(QPaintEvent *event) override;

private slots:
    void onLoginClicked();
    void handleLoginResponse(const QJsonObject &response);
    void onRegisterClicked();
    void animateButton(QWidget *button);

private:
    Ui::LoginDialog *ui;
    ClientNetwork *m_clientNetwork;
    RequestSender *m_requestSender;
    QPoint m_dragPosition;
    QPropertyAnimation *createButtonAnimation(QWidget *target);
};

#endif // LOGINDIALOG_H
